package com.member.web.controller.shop;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.member.common.annotation.Log;
import com.member.common.core.controller.BaseController;
import com.member.common.core.domain.AjaxResult;
import com.member.common.core.page.TableDataInfo;
import com.member.common.enums.BusinessType;
import com.member.common.utils.poi.ExcelUtil;
import com.member.shop.domain.SysBizRaffleActivityPrize;
import com.member.shop.domain.SysBizRaffleResults;
import com.member.shop.service.ISysBizRaffleResultsService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 抽奖结果Controller
 *
 * @author thomas
 * @date 2024-03-21
 */
@RestController
@RequestMapping("shop/raffle/results")
public class SysBizRaffleResultsController extends BaseController {
    @Resource
    private ISysBizRaffleResultsService sysBizRaffleResultsService;

    private void setTenantId(SysBizRaffleResults sysBizRaffleResults) {
        Long tenantId = getTenantId();
        if (tenantId != null && tenantId > 0) {
            sysBizRaffleResults.setTenantId(tenantId);
        }
    }

    /**
     * 查询抽奖结果列表
     */
    @PreAuthorize("@ss.hasPermi('raffle:results:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBizRaffleResults sysBizRaffleResults) {
        startPage();
        setTenantId(sysBizRaffleResults);
        List<SysBizRaffleResults> list = sysBizRaffleResultsService.selectSysBizRaffleResultsList(sysBizRaffleResults);
        return getDataTable(list);
    }

    /**
     * 导出抽奖结果列表
     */
    @PreAuthorize("@ss.hasPermi('raffle:results:export')")
    @Log(title = "抽奖结果", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBizRaffleResults sysBizRaffleResults) {
        setTenantId(sysBizRaffleResults);
        List<SysBizRaffleResults> list = sysBizRaffleResultsService.selectSysBizRaffleResultsList(sysBizRaffleResults);
        ExcelUtil<SysBizRaffleResults> util = new ExcelUtil<SysBizRaffleResults>(SysBizRaffleResults.class);
        util.exportExcel(response, list, "抽奖结果数据");
    }

    /**
     * 获取抽奖结果详细信息
     */
    @PreAuthorize("@ss.hasPermi('raffle:results:query')")
    @GetMapping(value = "/{resultId}")
    public AjaxResult getInfo(@PathVariable("resultId") Long resultId) {
        return success(sysBizRaffleResultsService.selectSysBizRaffleResultsByResultId(resultId));
    }

    /**
     * 新增抽奖结果
     */
    @PreAuthorize("@ss.hasPermi('raffle:results:add')")
    @Log(title = "抽奖结果", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBizRaffleResults sysBizRaffleResults) {
        return toAjax(sysBizRaffleResultsService.insertSysBizRaffleResults(sysBizRaffleResults));
    }

    /**
     * 修改抽奖结果
     */
    @PreAuthorize("@ss.hasPermi('raffle:results:edit')")
    @Log(title = "抽奖结果", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBizRaffleResults sysBizRaffleResults) {
        return toAjax(sysBizRaffleResultsService.updateSysBizRaffleResults(sysBizRaffleResults));
    }

    /**
     * 删除抽奖结果
     */
    @PreAuthorize("@ss.hasPermi('raffle:results:remove')")
    @Log(title = "抽奖结果", businessType = BusinessType.DELETE)
    @DeleteMapping("/{resultIds}")
    public AjaxResult remove(@PathVariable Long[] resultIds) {
        return toAjax(sysBizRaffleResultsService.deleteSysBizRaffleResultsByResultIds(resultIds));
    }
}
